package com.sun.mapper;

import com.github.pagehelper.Page;
import com.sun.annotation.AutoFill;
import com.sun.dto.ArtworkPageQueryDTO;
import com.sun.entity.Artwork;
import com.sun.enumeration.OperationType;
import com.sun.vo.ArtworkVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface ArtworkMapper {

    /**
     * 根据分类id查询艺术品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from artwork where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    /**
     * 插入艺术品数据
     * @param artwork
     */
    @AutoFill(value = OperationType.INSERT)
    void insert(Artwork artwork);

    /**
     * 艺术品分页查询
     * @param artworkPageQueryDTO
     * @return
     */
    Page<ArtworkVO> pageQuery(ArtworkPageQueryDTO artworkPageQueryDTO);

    /**
     * 根据主键查询艺术品
     * @param id
     * @return
     */
    @Select("select * from artwork where id = #{id}")
    Artwork getById(Long id);


    /**
     * 根据主键删除艺术品数据
     * @param id
     */
    @Delete("delete from artwork where id = #{id}")
    void deleteById(Long id);

    /**
     * 根据id动态修改艺术品数据
     * @param artwork
     */
    void update(Artwork artwork);

    /**
     * 动态条件查询艺术品
     * @param artwork
     * @return
     */
    List<Artwork> list(Artwork artwork);

    /**
     * 根据套餐id查询艺术品
     * @param setmealId
     * @return
     */
    @Select("select a.* from artwork a left join setmeal_artwork b on a.id = b.artwork_id where b.setmeal_id = #{setmealId}")
    List<Artwork> getBySetmealId(Long setmealId);


    /**
     * 根据条件统计艺术品数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
